package cn.iocoder.yudao.module.yyzx.service.nurse_level_content;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content.vo.Level_ContentPageReqVO;
import cn.iocoder.yudao.module.yyzx.controller.admin.nurse_level_content.vo.Level_ContentSaveReqVO;
import cn.iocoder.yudao.module.yyzx.controller.admin.outgoing.vo.OutgoingPageReqVO;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.content.ContentDO;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.level.LevelDO;
import cn.iocoder.yudao.module.yyzx.dal.dataobject.retreat.RetreatDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.val;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import cn.iocoder.yudao.module.yyzx.dal.mysql.level.*;

import java.util.List;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.yyzx.enums.ErrorCodeConstants.OUTGOING_NOT_EXISTS;

/**
 * 外出登记 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class LevelContentServiceImpl implements Level_ContentService {

    @Resource
    private cn.iocoder.yudao.module.yyzx.dal.mysql.level.LevelMapper levelMapper;
    @Resource
    private cn.iocoder.yudao.module.yyzx.dal.mysql.content.ContentMapper contentMapper;

    @Override
    public Integer createLevel_Content(Level_ContentSaveReqVO createReqVO) {
        // 插入
        LevelDO level = BeanUtils.toBean(createReqVO, LevelDO.class);
        levelMapper.insert(level);
        // 返回
        return level.getId();


    }

    @Override
    public void updateLevel_Content(Level_ContentSaveReqVO updateReqVO) {
        // 校验存在
        validateLevel_ContentExists(updateReqVO.getId());
        // 更新
        LevelDO updateObj = BeanUtils.toBean(updateReqVO, LevelDO.class);
        levelMapper.updateById(updateObj);
    }

    @Override
    public void deleteLevel_Content(Integer id) {
        // 校验存在
        validateLevel_ContentExists(id);
        // 删除
        levelMapper.deleteById(id);
    }

    @Override
    public PageResult<Level_ContentPageReqVO> getContentByLevelId(Integer id) {
        PageResult<Level_ContentPageReqVO> resvo = levelMapper.getListById(id);
        return resvo;
    }

    private void validateLevel_ContentExists(Integer id) {
        if (levelMapper.selectById(id) == null) {
            throw exception(OUTGOING_NOT_EXISTS);
        }
    }

//    @Override
//    public Level_ContentRespVO getLevel_Content(Integer id) {
//        return levelMapper.selectByRetreatId(id);
//    }

    @Override
    public PageResult<Level_ContentPageReqVO> getLevel_ContentPage(Level_ContentPageReqVO pageReqVO) {
        return null;
    }
}